#include "main.h"
using namespace std;

void registerRoutes(crow::SimpleApp& app) {
    CROW_ROUTE(app, "/api/locations").methods("GET"_method)
        ([](const crow::request& req) {
        const char* keyword = req.url_params.get("keyword") ? req.url_params.get("keyword") : "";
        int sortby = req.url_params.get("sortby") ? atoi(req.url_params.get("sortby")) : 1;
        int type = req.url_params.get("type") ? atoi(req.url_params.get("type")) : 0;
        int limit = req.url_params.get("limit") ? atoi(req.url_params.get("limit")) : 10;
        int offset = req.url_params.get("offset") ? atoi(req.url_params.get("offset")) : 0;

        auto result = locationEntry(keyword, sortby, type, limit, offset);

        // 添加分页元数据
        result["meta"]["page_size"] = limit;
        result["meta"]["current_offset"] = offset;

        return crow::response(result);
            });
}
